package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.domain.ProductCategory;
import com.itheima.manager.PmsProductCategoryManager;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.ProductCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class PmsProductCategoryController {
    @Autowired
    PmsProductCategoryManager pmsProductCategoryManager;

    //分页查询商品分类
    @GetMapping("/productCategory/list/{parentId}")
    public R<PageBeanVo> findByParentIdAndPage(@PathVariable Long parentId,
                                               @RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                               @RequestParam(value="pageSize",defaultValue = "5")Integer pageSize){
        return pmsProductCategoryManager.findByParentIdAndPage(parentId,pageNum,pageSize);
    }

    //添加商品分类
    @PostMapping("/productCategory/create")
    public R<String> saveProductCategory(@RequestBody ProductCategoryVo productCategoryVo){
        return pmsProductCategoryManager.saveProductCategory(productCategoryVo);
    }

    //删除商品分类
    @PostMapping("/productCategory/delete/{id}")
    public R<String> deleteProductCategory(@PathVariable Long id){
        return pmsProductCategoryManager.deleteProductCategory(id);
    }

    //查询所有一级分类及子分类
    @GetMapping("/productCategory/list/withChildren")
    public R<List<ProductCategoryVo>> findTreeCategory(){
        return pmsProductCategoryManager.findTreeCategory();
    }

    //修改导航栏显示状态
    @PostMapping("/productCategory/update/navStatus")
    public R<String> updateNavStatus(String ids,Integer navStatus){
        return pmsProductCategoryManager.updateNavStatus(ids,navStatus);
    }

    //修改显示状态
    @PostMapping("/productCategory/update/showStatus")
    public R<String> updateShowSatus(String ids,Integer showStatus){
        return pmsProductCategoryManager.updateShowStatus(ids,showStatus);
    }

    //修改商品分类
    @PostMapping("/productCategory/update/{id}")
    public R<String> updateCategory(@PathVariable Long id,@RequestBody ProductCategoryVo productCategoryVo){
        return pmsProductCategoryManager.updateCategory(productCategoryVo);
    }

    //根据id获取商品分类
    @GetMapping("/productCategory/{id}")
    public R<ProductCategory> findById(@PathVariable Long id){
        return pmsProductCategoryManager.findById(id);
    }
}
